//
//  HMMainViewController.swift
//  GuoGuo
//
//  Created by 艾小新 on 16/7/29.
//  Copyright © 2016年 xiaoxin. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 这里用KVC赋值
        let mytabBar = HMTabBarView()
        
        mytabBar.composeClick = {

            
            // View控件创建
            let comView = HMComposeView()
            comView.show(self)
            
            
        }
        self.setValue(mytabBar, forKey: "tabBar")
        

        ///  这里设置初始启动后，有四个页面
        addChildViewController(HMHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(HMMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(HMDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(HMProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
        //  UITabBar.appearance().tintColor = UIColor.orangeColor()
        
    }
    
    ///  添加四个子控制器
    ///
    ///  - parameter childController: 控制器名称
    ///  - parameter imageName:       tabBarItem图片
    ///  - parameter titleName:       tabBarItem名称
    func addChildViewController(childController: UIViewController , title: String, imageName: String) {
        // 设置颜色
        // 修改成自己的   
        childController.tabBarItem = HMTabBarItem()
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(10)], forState: .Normal)
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(22)], forState: .Selected)
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        childController.tabBarItem.title = title
        childController.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(.AlwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named:"\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        let nav = HMNavgationController(rootViewController: childController)
        childController.navigationItem.title = title
        addChildViewController(nav)
    }


    


}
